package cn.enited.devtools.apiaggregator.dto;

import cn.enited.devtools.apiaggregator.anno.IsBizId;
import cn.enited.devtools.apiaggregator.validator.group.CreateValidationGroup;
import cn.enited.devtools.apiaggregator.validator.group.DeleteValidationGroup;
import cn.enited.devtools.apiaggregator.validator.group.UpdateValidationGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Data
public class ApiAggObjectDto implements Serializable {
    private static final long serialVersionUID = -2298653092791190907L;

    @NotNull(groups = {UpdateValidationGroup.class, DeleteValidationGroup.class}, message = "缺少id标识")
    @IsBizId(groups = {UpdateValidationGroup.class, DeleteValidationGroup.class}, message = "无效的id")
    private Long bizId;

    @NotBlank(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "名称不能为空")
    private String name;

    @NotNull(groups = {UpdateValidationGroup.class, DeleteValidationGroup.class}, message = "缺少id标识")
    @IsBizId(groups = {UpdateValidationGroup.class, DeleteValidationGroup.class}, message = "无效的id")
    private Long projectId;

    private String projectName;

    @NotBlank(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "描述不能为空")
    private String description;

    @NotEmpty(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "服务列表不能为空")
    private List<Entry> services;

    private Date createDate;

    private Date updateDate;

    @Data
    public static class Entry implements Serializable {
        private static final long serialVersionUID = 428232955766966099L;

        @NotBlank(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "service id不能为空")
        private String id;

        @NotBlank(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "service path不能为空")
        private String path;

        @NotBlank(groups = {CreateValidationGroup.class, UpdateValidationGroup.class}, message = "service method不能为空")
        private String method;

        private String dataType;

        private Map<String, String> head;

        private Map<String, Object> data;
    }
}
